<template>
  <div class="home">
    <!-- <home_header :isLogin="isLogin" :isEpLogin="isEpLogin"></home_header> -->
    <home_search></home_search>
    <home_nav></home_nav>
    <div class="content">
      <transition name="move" mode="out-in">
        <!-- <keep-alive :include="tagsList"> -->
        <router-view></router-view>
        <!-- </keep-alive> -->
      </transition>

    </div>
    <rightPopover :isLogin="isLogin" :isEpLogin="isEpLogin" />
    <!-- <router-view></router-view> -->
    <footer-menu></footer-menu>
    <el-backtop></el-backtop>
  </div>
</template>

<script>


import { enterpriseToken, personalToken } from '../../api/index';
import bus from '../common/bus';
export default {
  name: '',
  data () {
    return {
      isLogin: false,
      isEpLogin: false
    };
  },
  created () {
    console.log(1);
    let ps = localStorage.getItem('ps_Authorization');
    let ep = localStorage.getItem('ep_Authorization');
    console.log(ps, ep);
    if (ps && ep) {
      enterpriseToken(ep)
        .then(data => {
          if (data.success) {
            console.log('企业都有');
            this.isEpLogin = true;
          } else {
            localStorage.removeItem('ep_Authorization');
            localStorage.removeItem('ep_userName');
          }
        })
        .catch(error => {
          localStorage.removeItem('ep_Authorization');
          localStorage.removeItem('ep_userName');
        });
      personalToken(ps)
        .then(data => {
          if (data.success) {
            this.isLogin = true;
            console.log('个人都有');
          } else {
            localStorage.removeItem('ps_Authorization');
            localStorage.removeItem('ps_userName');
          }
        })
        .catch(error => {
          localStorage.removeItem('ps_Authorization');
          localStorage.removeItem('ps_userName');
        });
    } else if (ps) {
      personalToken(ps)
        .then(data => {
          if (data.success) {
            this.isLogin = true;
            console.log('企业');
          } else {
            localStorage.removeItem('ps_Authorization');
            localStorage.removeItem('ps_userName');
          }
        })
        .catch(error => {
          localStorage.removeItem('ps_Authorization');
          localStorage.removeItem('ps_userName');
        });
    } else if (ep) {
      enterpriseToken(ep)
        .then(data => {
          if (data.success) {
            this.isEpLogin = true;
            console.log('个人');
          } else {
            localStorage.removeItem('ep_Authorization');
            localStorage.removeItem('ep_userName');
          }
        })
        .catch(error => {
          localStorage.removeItem('ep_Authorization');
          localStorage.removeItem('ep_userName');
        });
    } else {
      localStorage.setItem('ep_Authorization', '');
      localStorage.setItem('ps_Authorization', '');
      localStorage.setItem('ps_userName', '');
      localStorage.setItem('ep_userName', '');
    }
    bus.$on('changeIsLogin', msg => {
      console.log(msg);
      this.isLogin = msg;
    });
    bus.$on('changeEpLogin', msg => {
      console.log(msg);
      this.isEpLogin = msg;
    });
  }
};
</script>

<style lang="css" scoped>
.home {
    width: 100%;
    background: #fff;
    opacity: 1;
}
</style>